﻿/**
   ActionScript Class File -- Created with SAPIEN Technologies PrimalScript 3.1
   
   @class  
   @package
   @author Colin Leung
   @codehint 
   @example 
   @tooltip 
*/


class com.mixmedia.control.SmartLabel{
	private var txtTarget;
	private var longText;
	private var shortText;
	public var isNeedToolTips:Boolean;
	
	public function SmartLabel(txf:TextField){//trim word and add tool tips.
		txtTarget = txf;
		// if text width > textfield width
		txtTarget.mulitline = false;
	}
	
	public function setText(txt:String){
		txtTarget.text = txt;
		if(txtTarget.textWidth+4 >= txtTarget._width){//+4 bcoz 2 px border, true= text overflow.
			isNeedToolTips = true;
		// get long name
			longText = String(txtTarget.text);
		//guess the general letter width;
			var estCellChar = Math.floor(txtTarget._width/(txtTarget.textWidth/longText.length))-5;
		// trim name
			shortText = longText.substr(0,estCellChar)+"...";
			//apply the short text to the textfield
			txtTarget.text = shortText;
		}else{
			isNeedToolTips = false;
		}	
	}
}
